﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using UIWindows.GlobalStatics;

namespace UIWindows.Tools.Converter
{
    [ValueConversion(typeof(bool), typeof(bool))]
    public class RoleControlConverter : IValueConverter
    {
        private UserConfigStatic _user;
        private DisplayItemsStatic _displayItems;
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (_user == null)
            {
                _user = Domains.ObjectContainer.ResolveSingleton<UserConfigStatic>();
                _displayItems = Domains.ObjectContainer.ResolveSingleton<DisplayItemsStatic>();
            }
            if (_user.LoginUser.Level == Enums.AuthorityTypes.管理员 || _user.LoginUser.Level == Enums.AuthorityTypes.超级管理员)
            {
                return true;
            }
            return _displayItems.RoleInit.Any(x => x.Authority == _user.LoginUser.Level && x.RoleName == parameter.ToString() && x.IsEnable);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {

            return true;
        }
    }
}
